package com.ccsoft.multds.controller;

import com.ccsoft.multds.annotion.WR;
import com.ccsoft.multds.config.DynamicDataSource;
import com.ccsoft.multds.entity.Goods;
import com.ccsoft.multds.service.GoodsService;
import com.ccsoft.multds.utils.MultDSSwitcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author chanchaw
 * @create 2022-09-16 11:12
 */
@CrossOrigin
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService service;

    @GetMapping("/select")
    public List<Goods> selectAll(){
//        DynamicDataSource.multDSSwitcher.set(MultDSSwitcher.READ);
        return service.selectAll();
    }

    @GetMapping("/insert")
    public Integer insert(){
//        DynamicDataSource.multDSSwitcher.set(MultDSSwitcher.WRITE);
        Goods goods = new Goods();
        goods.setSid(new Date().toString());
        return service.insertSelective(goods);
    }
}
